<template>
  <view :data-theme="globPrimary">
    <u-navbar title="设置" :custom-back="onBack"></u-navbar>
    <!-- 列表 -->
    <view class="user-cell">
      <u-cell-group :border="false">
        <block v-if="hasLogin">
          <u-cell-item
            title="设置登录密码"
            :title-style="titleStyle"
            hover-class="none"
            @click="onTokenJump('/pageUser/setting/editPwd')"
            v-if="globUserInfo.need_set_password == 1"
          ></u-cell-item>
          <u-cell-item
            v-else
            title="修改登录密码"
            :title-style="titleStyle"
            hover-class="none"
            @click="onTokenJump('/pageUser/setting/modifyPwd')"
          ></u-cell-item>
          <u-cell-item
            title="设置支付密码"
            :title-style="titleStyle"
            hover-class="none"
            @click="onTokenJump('/pageUser/setting/editPayPwd')"
            v-if="globUserInfo.need_set_paypwd == 1"
          ></u-cell-item>
          <u-cell-item
            title="修改支付密码"
            :title-style="titleStyle"
            hover-class="none"
            @click="onTokenJump('/pageUser/setting/modifyPayPwd')"
            v-else
          ></u-cell-item>
        </block>
        <!-- #ifndef MP-WEIXIN -->
        <u-cell-item
          title="第三方账号"
          :title-style="titleStyle"
          hover-class="none"
          @click="onTokenJump('/pageUser/setting/thirdlogin')"
        ></u-cell-item>
        <!-- #endif -->
        <block v-if="hasLogin">
          <u-cell-item
            title="地址管理"
            :title-style="titleStyle"
            :border-bottom="false"
            hover-class="none"
            @click="onTokenJump('/pageUser/address/index')"
          ></u-cell-item>
        </block>
        <u-gap height="10" bg-color="#F7F7F7"></u-gap>
        <!-- #ifndef H5 -->
        <u-cell-item
          title="机构切换"
          :title-style="titleStyle"
          hover-class="none"
          v-if="getGlobSchoolSwitch == 1"
          @click="$u.route('/pageUser/setting/schoolSearch')"
        ></u-cell-item>
        <!-- #endif -->
        <u-cell-item
          title="关于我们"
          :title-style="titleStyle"
          :border-bottom="false"
          hover-class="none"
          @click="$u.route('/pages/protocol', { key: 'aboutUs' })"
        ></u-cell-item>
        <u-cell-item
          title="隐私政策"
          :title-style="titleStyle"
          :border-bottom="false"
          hover-class="none"
          @click="$u.route('/pages/protocol', { key: 'userPrivacy' })"
        ></u-cell-item>
        <!-- userPrivacy -->
        <u-gap height="10" bg-color="#F7F7F7"></u-gap>
        <u-cell-item
          title="退出账号"
          :title-style="titleStyle"
          :arrow="false"
          :border-bottom="false"
          hover-class="none"
          @click="logoutModal = true"
          v-if="hasLogin"
        ></u-cell-item>
        <u-cell-item
          title="登录"
          :title-style="titleStyle"
          :arrow="false"
          :border-bottom="false"
          hover-class="none"
          v-else
          @click="onTokenJump('/pageUser/login/index')"
        ></u-cell-item>
      </u-cell-group>
    </view>
    <u-modal
      show-cancel-button
      v-model="logoutModal"
      :show-title="false"
      :confirm-style="{ 'border-left': '1px solid #e4e7ed' }"
      confirm-color="#f54030"
      @confirm="confirm"
    >
      <view class="u-text-center u-font-32 u-main-color u-padding-top-70 u-padding-bottom-60"
        >确定要退出登录吗？</view
      >
    </u-modal>
    <edu-user-coupon></edu-user-coupon>
  </view>
</template>

<script>
import { mapGetters } from 'vuex'
export default {
  data() {
    return {
      titleStyle: {
        'font-size': '30rpx',
        color: '#303133',
      },
      logoutModal: false,
    }
  },
  computed: {
    ...mapGetters({
      globPrimary: 'designSetting/getGlobTheme',
      globPrimaryColor: 'designSetting/getGlobThemeColor',
      getGlobSchoolSwitch: 'projectSetting/getGlobSchoolSwitch',
      hasLogin: 'user/getHasLogin',
      globUserInfo: 'user/getUserInfo',
    }),
  },
  // 监听页面返回
  onBackPress(options) {
    if (options.from === 'navigateBack') {
      return false
    }
    this.onBack()
    return true
  },
  methods: {
    // 点击之前判断用户是否登录
    onTokenJump(url, params) {
      this.$edu.judgeLogin(() => {
        this.$u.route(url, params)
      })
    },
    // 退出登录
    confirm() {
      this.$store.dispatch('user/logout')
      this.$u.route({
        url: '/pageUser/login/index',
      })
    },
    // 返回上一页
    onBack() {
      let pages = getCurrentPages()
      let page = pages[pages.length - 2]
      if (this.$u.test.empty(page)) {
        this.$u.route({ type: 'switchTab', url: 'pages/user/index' })
      } else {
        this.$u.route({ type: 'back' })
      }
    },
  },
}
</script>

<style lang="scss">
page {
  background: #f7f7f7;
}
/* #ifdef APP-PLUS */
/deep/.u-close {
  top: 80rpx !important;
}
/* #endif */
.user-cell {
  width: 100%;
  overflow: hidden;
  .u-border-bottom:after {
    left: 32rpx;
  }
  .u-cell-box + .u-cell-box {
    margin-top: 18rpx;
  }
  .u-border-bottom:last-child:after {
    display: none;
  }
}
/* #ifdef MP-WEIXIN */
/deep/.u-close--top-left.data-v-4b631af3 {
  margin-top: 50rpx;
}
/* #endif */
</style>
